/**
 * 班级管理初始化
 */
var SeniorSchoolClass = {
    id: "SeniorSchoolClassTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
SeniorSchoolClass.initColumn = function () {
    return [
            {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
            {title: '所属学校', field: 'schoolName', visible: true, align: 'center', valign: 'middle'},
            {title: '班级代号', field: 'seniorClassCode', visible: true, align: 'center', valign: 'middle'},
            {title: '班级名称', field: 'senoirClassName', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
SeniorSchoolClass.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        SeniorSchoolClass.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加班级
 */
SeniorSchoolClass.openAddClass = function () {
    var index = layer.open({
        type: 2,
        title: '添加班级',
        area: ['500px', '500px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/seniorSchoolClass/edit'
    });
    this.layerIndex = index;
};

/**
 * 打开查看班级详情
 */
SeniorSchoolClass.openChangeClass = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '修改班级',
            area: ['500px', '500px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/seniorSchoolClass/edit?id=' + SeniorSchoolClass.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除班级
 */
SeniorSchoolClass.delSchool = function () {
    if (this.check()) {
    	 var operation = function(){
	        var ajax = new $ax(Feng.ctxPath + "/seniorSchoolClass/remove", function (data) {
	            Feng.success("删除成功!");
	            SeniorSchoolClass.table.refresh();
	        }, function (data) {
	            Feng.error("删除失败!" + data.responseJSON.message + "!");
	        });
	        ajax.set("classId",SeniorSchoolClass.seItem.id);
	        ajax.start();
    	 };
    	 Feng.confirm("是否删除班级 " + SeniorSchoolClass.seItem.senoirClassName + "？",operation);
    }
};

SeniorSchoolClass.resetSearch = function () {
    $("#seniorSchoolId").val("").trigger("change");
    $("#seniorClassCode").val("");
    $("#senoirClassName").val("");
    SeniorSchoolClass.search();
}

/**
 * 查询班级列表
 */
SeniorSchoolClass.search = function () {
    var queryData = {};
    queryData['seniorClassCode'] = $("#seniorClassCode").val();
    queryData['senoirClassName'] = $("#senoirClassName").val();
    queryData['seniorSchoolId'] = $("#seniorSchoolId").select2("val");
    SeniorSchoolClass.table.refresh({query: queryData});
};

$(function () {
    var defaultColumns = SeniorSchoolClass.initColumn();
    var table = new BSTable(SeniorSchoolClass.id, "/seniorSchoolClass/list", defaultColumns);
    SeniorSchoolClass.table = table.init();
});
